"use strict";
cc._RF.push(module, '75e9dkU4rhERab5E2YqTFnp', 'NPCKingController');
// scripts/NPCKingController.js

"use strict";

var e = require;
var t = module;
var n = i(e("RecorderPanel")),
    o = i(e("SoundMgr"));

function i(e) {
  return e && e.__esModule ? e : {
    "default": e
  };
}

window.NPCKingController = {
  Instance: null
};
var a = e("LevelManager"),
    r = e("DeathController");
cc.Class({
  "extends": cc.Component,
  properties: {
    DeathController: r,
    ControllerAnimation: dragonBones.ArmatureDisplay,
    _CurrentIsDiscover: !1,
    CurrentIsDiscover: {
      get: function get() {
        return this._CurrentIsDiscover;
      },
      set: function set(e) {
        this._CurrentIsDiscover = e;
        this.onControllerDiscoverStatusChange();
      }
    }
  },
  onLoad: function onLoad() {
    NPCKingController.Instance = this;
  },
  start: function start() {
    CameraManager.Instance.CameraTarget = this.node;
    this.ControllerAnimation.addEventListener(dragonBones.EventObject.START, function () {
      "back" == this.ControllerAnimation.animationName && this.AFUNC_LeftLook();
    }.bind(this), this);
    this.scheduleOnce(this.RandomKingAnims, 2);
  },
  onDestroy: function onDestroy() {
    NPCKingController.Instance = null;
  },
  update: function update(e) {
    n["default"].GamePause || LevelManager.Instance.AllowAvatarControllerMove && (this.node.x += LevelManager.Instance.AvatarControllerMoveSpeed * e);
  },
  Death: function Death(e) {
    this.DeathController.DeathFunction(e);
    this.node.destroy();
  },
  RandomKingAnims: function RandomKingAnims() {
    this.unschedule(this.RandomKingAnimsCallback);
    this.RandomKingAnimsCallback = this.scheduleOnce(function () {
      this.RandomKingAnims();
    }, Math.round(Math.round(5 * Math.random() + 3)));

    if (!(KillerController.Instance.node.position.sub(this.node.position).mag() >= LevelManager.Instance.AvatarControllerDistanceMinLimit || LevelManager.Instance.AttackProgressBar.progress >= .82 || this.CurrentIsDiscover)) {
      this.ControllerAnimation.playAnimation("walk", 0);
      var e = Math.round(Math.round(14 * Math.random()));
      e >= 0 && e <= 2 ? this.ControllerAnimation.playAnimation("walk", 0) : e >= 3 && e <= 4.5 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 6 && e <= 6.8 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 8 && e <= 8.8 ? this.ControllerAnimation.playAnimation("back", 1) : e >= 10 && e <= 12 && this.ControllerAnimation.playAnimation("back", 1);
    }
  },
  AFUNC_LeftLook: function AFUNC_LeftLook() {
    if (!(LevelManager.Instance.AttackProgressBar.progress >= .82 || this.CurrentIsDiscover)) {
      cc.log("llook func");
      o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[7]);
      LevelManager.Instance.AllowAvatarControllerMove = !1;
      LevelManager.Instance.GameAllowOperation = !1;
      this.CurrentIsDiscover = !0;
      this.unschedule(this.AFUNC_LeftLookOverCallback);
      this.AFUNC_LeftLookOverCallback = this.scheduleOnce(this.AFUNC_LeftLookOver, Math.round(Math.round(2 * Math.random() + 2)));
    }
  },
  AFUNC_LeftLookOver: function AFUNC_LeftLookOver() {
    if (!(LevelManager.Instance.AttackProgressBar.progress >= .9) && LevelManager.Instance.GameCurrentOperationScene != a.GameSceneBlockType.Jail) {
      cc.log("llookover");
      LevelManager.Instance.AllowAvatarControllerMove = !0;
      LevelManager.Instance.GameAllowOperation = !0;
      this.ControllerAnimation.playAnimation("walk", 0);
      this.CurrentIsDiscover = !1;
    }
  },
  AFUNC_Cough: function AFUNC_Cough() {
    o["default"].Instance.playSoundClip(AssetManager.Instance.AudioClips[2]);
  },
  onControllerDiscoverStatusChange: function onControllerDiscoverStatusChange() {
    this.CurrentIsDiscover ? LevelManager.Instance.AttackProgressBar.progress > 0 ? KillerController.Instance.onNonSafeKingDiscoverFunction() : KillerController.Instance.onSafeKingDiscoverFunction() : KillerController.Instance.onSafeKingDiscoverFunctionOver();
  },
  onJailSceneFinish: function onJailSceneFinish() {
    this.AFUNC_LeftLookOver();
  }
});

cc._RF.pop();